#!/bin/bash
set -e

function info() {
echo Usage: `basename $0` '[-s sample_name] <fq [...]>'
exit 65
}

while getopts  ":s:p:h" opts
do
        case  $opts  in
		s) sample_name=$OPTARG;;
		p) out_prefix=$OPTARG;;
		*) info;;
		esac
done
shift $(($OPTIND - 1))

if [ -z "$1" ]; then info; fi



. /mnt/ilustre/app/medical/tools/.var

for fq in $@; do


fq_pre=`basename $fq`

#Q20stat ----
echo -e 'fq\ttotal bases\tbases >=q20\t%' > $fq_pre.q20.txt;
java $tmp -jar $tools_path/FastqTotalHighQualityBase.jar -i $fq >> $fq_pre.q20.txt;


#quality control
if
echo $fq |grep 'gz$'
then
zcat $fq |fastx_quality_stats -Q33 > $fq_pre.fq_stat.txt
else
cat $fq |fastx_quality_stats -Q33 > $fq_pre.fq_stat.txt
fi
# fastq_quality_boxplot_graph.sh -i $fq.fq_stat.txt -t 'title test' -p -o $fq.graph.ps
# fastx_nucleotide_distribution_graph.sh -i $fq.fq_stat.txt -t 'title test' -p -o $fq.base_distri.graph.ps

# ps2pdf $fq.graph.ps
# ps2pdf $fq.base_distri.graph.ps

Rscript $tools_path/script/fqs.r $fq_pre.fq_stat.txt $fq_pre

done

# fastq_quality_filter -Q33 -q20 -p90 -i L001s001.1.cut.fastq -o 1.filt.fq

# fasta_clipping_histogram.pl
